import Vue from 'vue'
import VueRouter from 'vue-router'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
import Layout from '../sfs-example/views/Layout.vue'
import Home from '../sfs-example/views/home/index.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Layout',
    component: Layout,
    redirect: '/Home',
    children: [
      {
        path: '/Home',
        name: 'Home',
        component: Home,
        meta: {
          title: '首页',
          rols: 'admin',
        },
      },
      {
        path: '/OneMap',
        name: 'OneMap',
        component: () =>
          import(
            /* webpackChunkName: "OneMap" */ '../sfs-example/views/onemap/index.vue'
          ),
        meta: {
          title: '一张图应用',
          rols: 'admin',
        },
      },
    ],
  },
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes,
})

router.beforeEach((to, from, next) => {
  NProgress.start()
  next()
})

router.afterEach(() => {
  NProgress.done()
})

export default router
